package com.kexio.dynamic.permission;

import com.kexio.dynamic.permission.rule.RuleEvaluator;
import com.kexio.dynamic.permission.rule.RuleParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import jakarta.annotation.PostConstruct;

/**
 * 动态权限模块自动配置
 * 
 * 功能说明：
 * - 自动配置权限引擎
 * - 自动配置规则解析器和评估器
 * - 启用动态权限注解支持
 * 
 * @author Kexio
 * @since 1.0.0
 */
@Configuration
@ConditionalOnProperty(name = "kexio.dynamic.permission.enabled", havingValue = "true", matchIfMissing = true)
public class DynamicPermissionAutoConfiguration {

    private static final Logger log = LoggerFactory.getLogger(DynamicPermissionAutoConfiguration.class);

    @PostConstruct
    public void init() {
        log.info("==> Kexio动态权限模块已启用");
        log.debug("动态权限模块包含: 权限引擎、规则解析器、权限注解、AOP切面");
    }

    /**
     * 规则解析器
     */
    @Bean
    @ConditionalOnMissingBean
    public RuleParser ruleParser() {
        log.debug("==> 创建RuleParser实例");
        return new RuleParser();
    }

    /**
     * 规则评估器
     */
    @Bean
    @ConditionalOnMissingBean
    public RuleEvaluator ruleEvaluator(RuleParser ruleParser) {
        log.debug("==> 创建RuleEvaluator实例");
        return new RuleEvaluator(ruleParser);
    }
}
